#ifndef TCP_CONNENCT_H
#define TCP_CONNENCT_H

#include "SocketIO.h"
#include "Socket.h"
#include "InetAddress.h"
#include <memory>
#include <iostream>
#include <arpa/inet.h>
#include <string.h>
#include <sstream>
#include <unistd.h>

using std::cout;
using std::endl;

class TcpConnect
    : public std::enable_shared_from_this<TcpConnect>
{
    using TcpConnectPtr = std::shared_ptr<TcpConnect>;
    using callback = std::function<void(TcpConnectPtr)>;

private:
    int _cltFd;
    SocketIO _io;

    callback _connectCallback;
    callback _handleMessageCallback;
    callback _closedCallback;

public:
    TcpConnect(int cltFd);
    TcpConnect(const TcpConnect &rhs);
    void send(const char *);
    std::string receive();
    InetAddress getPeerAddress() const;
    InetAddress getLocalAddress() const;
    const std::string toString() const;
    void shutdown();

    void setClosedCallback(callback cb);
    void setMessageCallback(callback cb);
    void setConnectCallback(callback cb);
    void handleClosed();
    void handleMessage();
    void handleConnect();
};

#endif